import { defineStore } from "pinia";

const useStore = defineStore('tag', {
    state: () => {
        return {
            tagList: [
                {
                    path: '/dashBoard',
                    name: 'dashBoard',
                    icon: 'shouyefill',
                    meta: { label: '首页' }
                },
            ]
        }
    },
    actions: {
        // 存数据
        INIT_LIST(info: any) {
            // 点击的不是首页且数组中没有再添加
            if(info.path !== '/dashBoard'){
                const index = this.tagList.findIndex(item => item.path === info.path)
                if(index === -1){
                    this.tagList.push(info)
                }
            }
        },
        // 删除
        DEL_LISt (info: { path: any; }) {
            // 找到要删除的数据在数组中的下标
              const index = this.tagList.findIndex((item: { path: any; }) => item.path === info.path)
              this.tagList.splice(index, 1)
            }
        
    }
})

export default useStore